""" This file will fill the things in the table=  "" """

#"""
database1 = "apsec2013"
user1 = "sangeetal"
password1 = "sangeetal"
port1= 3307

"""
=============
database1 = "apsec2013"
user1 = "root"
password1 = "123"
port1= 3306
#==="""

import MySQLdb
store_table = "result_issue_comment_link"
comment_table = "temp_issue_comment"
desc_link_table = "temp_issue_desc_link"
comment_link_table = "temp_issue_comment_link"

db1= MySQLdb.connect(host="localhost", user=user1, passwd=password1,db=database1, port=port1)
get_cursor = db1.cursor()
temp_cursor = db1.cursor()

str1 = "select issue_id from " + store_table  + " where issue_id >=59000 " #till  59156 #till 60136

get_cursor.execute(str1)

issues = get_cursor.fetchall()
count = 0
for id in issues:
    issue = id[0]
    print issue
    temp_str1   = "select  No_of_comments from " +  comment_table+"  where issue_id =  "+(str)(issue)
    temp_cursor.execute(temp_str1)
    No_of_comments = 0
    No_of_comments =temp_cursor.fetchall()
    #print "len", len(No_of_comments)
    if len(No_of_comments)>0:
        No_of_comments = No_of_comments[0][0]
    else:   
         No_of_comments = 0
    
    temp_str2=  "select desc_link from  "+ desc_link_table + " where issue_id="+(str)(issue)
    temp_cursor.execute(temp_str2)
    desc_link_count=0
    desc_link_count = temp_cursor.fetchall()
    print "desc link count=", len(desc_link_count)
    if len(desc_link_count) >0:
        desc_link_count = desc_link_count[0][0] 
    else:
         desc_link_count=0    

    
    temp_str3= "select No_of_links from "+ comment_link_table +" where issue_id ="+(str)(issue)
    temp_cursor.execute(temp_str3)
    comment_link_count=0
    comment_link_count = temp_cursor.fetchall()
    if len(comment_link_count)>0:
        comment_link_count = comment_link_count[0][0] 
    else:
        comment_link_count=0    
    
    
    print "issue =", issue #, " Comment=", No_of_comments, " desc link=", desc_link_count, "comment_link=", comment_link_count
    
    #update_str = "update  "+ store_table +" set  comment_count="+(str)(No_of_comments)+  " where issue_id="+(str)(issue)
    update_str = "update  "+ store_table +" set  comment_count="+(str)(No_of_comments)+ ",  link_count_desc="+(str)(desc_link_count)+\
    ", link_count_comment= "+(str)(comment_link_count)+ " where issue_id="+(str)(issue)
    
    #print "update_str" , update_str
    temp_cursor.execute(update_str)
    count = count +1
    if count >=500: 
        db1.commit()
        count = 0